package com.providera;

import cn.hutool.core.lang.Console;
import cn.hutool.core.thread.ThreadUtil;
import com.register.client.RegisterUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;

import static com.providera.ProviderAApplication.SOCKET_PORT;

@Component
@Import(RegisterUtil.class)
public class RegisterRunner implements ApplicationRunner {

    @Autowired
    RegisterUtil registerUtil;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        ThreadUtil.execAsync(()->{
            while (true){
                try {
                    registerUtil.registerApi("com.providera.service.UserService#getInfo","127.0.0.1", SOCKET_PORT);
                    ThreadUtil.safeSleep(3000L);
                }catch (Exception e){
                    Console.error(e);
                }
            }
        });
    }
}
